<?php
namespace App\Http\Controllers;

use pay\AlipayAPI\AlipayEncryption;

class AlipayController extends Controller
{

    public function __construct()
    {
//		$this->gate_url = 'https://openapi.alipay.com/gateway.do';
        $this->appid = config('alipay.appid');
        $this->pid = config('alipay.pid');
//		$this->public_key  = config('alipay.public_key');
//		$this->private_key = config('alipay.private_key');
        $this->private_key = config('alipay.private_key');
        $this->encpt = new AlipayEncryption($this->private_key); //实例化签名类
        $this->alipayPubKeyFile = config('alipay.alipay_pubic_key');

    }

    public function aliPayQuery()
    {
        //请求参数
        $dataQuery = [
            'out_trade_no' => '21321321312321312345678900',
            'product_code' => 'FAST_INSTANT_TRADE_PAY',
            'total_amount' => 100,
            'subject'      => 'test'
            //'body' => 'test'
        ];

        //公共参数
        $dataCommon = [
            'method'      => 'alipay.trade.page.pay',
            'app_id'      => $this->appid,
            'version'     => '1.0',
            'sign_type'   => 'RSA',
            'charset'     => 'UTF-8',
            'format'       => 'json',
            'timestamp'   => date("Y-m-d H:i:s"),
            'biz_content' => json_encode($dataQuery),
        ];
        $type = 'POST';
        $res  = $this->encpt->aliPayQuery($dataCommon, $type);

        if ($type == 'POST') {
            echo $res;
        } else {
            dd($res);
        }
    }


}
